package wap.io;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;

/**
 * @描述：tar.gz用TarArchiveInputStream类读出现问题，直接模拟使用gz
 * @作者：hongxingfan
 * @时间：2014年9月19日 下午2:54:17
 */
public class BufferedGzipReader {
	private String fileName;
	private BufferedReader br = null;

	public BufferedGzipReader(String fileName) {
		this.fileName = fileName;
		try {
			br = new BufferedReader(new InputStreamReader(new BufferedInputStream(new GZIPInputStream(
			        new FileInputStream(this.fileName)))));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String readLine() throws IOException {
		return br.readLine();
	}

	public String getName() {
		return this.fileName.substring(this.fileName.lastIndexOf("\\") + 1, this.fileName.lastIndexOf(".gz"));
	}

	public void close() {
		if (br != null) {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
